<?php $this->load->view('templates/backend/header'); ?>
<h3><?php echo 'Chuyển số dư cho khách hàng từ A sang B';?></h3>
<style>
    .num_cls{
        width:20%;
    }
    .btn-success,.btn-danger{
        vertical-align: top;
    }
    .notice{
        color:green;
    }
    .navbar-inverse{
        display: none;
    }
    body{
        padding-top:10px;
        padding-bottom:30px;
    }
</style>

<div class="well">
    <?php echo form_open();?>
        <div class="tab-content">	
            <div class="tab-pane active" id="main">
                <?php
                //thông tin booker gởi
                echo form_label('Thông tin tài khoản gởi', '');
                
                echo form_label($this->lang->line('booker'), 'booker_send');
                echo form_dropdown('booker_send', $booker, ($info->owner)?$info->owner:'','id="booker_send"');
                echo form_error('booker_send');
                
                echo form_label($this->lang->line('phone'), 'phone_send');
                echo form_input(array('name' => 'phone_send', 'id' => 'phone_send', 'value' => ($info->phone_send)?$info->phone_send:'','required'=>'required','placeholder'=>$this->lang->line('phone'),'readonly' => 'true'));
                echo form_error('phone_send');
                
                echo form_label($this->lang->line('customerID'), 'customerID_send');
                echo form_input(array('name' => 'customerID_send', 'id' => 'customerID_send', 'value' => ($info->customerID_send)?$info->customerID_send:'','required'=>'required','placeholder'=>$this->lang->line('customerID'),'readonly' => 'true'));
                echo form_error('customerID_send');
                
                echo form_label($this->lang->line('amount'), 'amount_send');
                echo form_input(array('name' => 'amount_send', 'id' => 'amount_send', 'value' => $info->amount_send,'required'=>'required','placeholder'=>$this->lang->line('amount')));
                echo form_input(array('type' => 'hidden','name' => 'amount_send_fake', 'id' => 'amount_send_fake', 'value' => $info->amount_send));
                echo form_error('amount_send');
                
                //thông tin booker nhận
                echo form_label('Thông tin tài khoản nhận', '');
                
                echo form_label($this->lang->line('booker'), 'booker_recieve');
                echo form_dropdown('booker_recieve', $booker, '','id="booker_recieve"');
                echo form_error('booker_recieve');
                
                echo form_label($this->lang->line('phone'), 'phone_recieve');
                echo form_input(array('name' => 'phone_recieve', 'id' => 'phone_recieve', 'value' => '','required'=>'required','placeholder'=>$this->lang->line('phone')));
                echo form_error('phone_recieve');
                
                echo form_label($this->lang->line('customerID'), 'customerID_recieve');
                echo form_input(array('name' => 'customerID_recieve', 'id' => 'customerID_recieve', 'value' => '','required'=>'required','placeholder'=>$this->lang->line('customerID')));
                echo form_error('customerID_recieve');
                
                echo form_label($this->lang->line('amount'), 'amount_recieve');
                echo form_input(array('name' => 'amount_recieve', 'id' => 'amount_recieve', 'value' => 0,'required'=>'required','placeholder'=>$this->lang->line('amount')));
                echo form_input(array('type' => 'hidden','name' => 'amount_recieve_fake', 'id' => 'amount_recieve_fake', 'value' => 0));
                echo form_error('amount_recieve');
                
                echo form_input(array('type' => 'hidden','name' => 'owner_send', 'id' => 'owner_send', 'value' => $info->owner));
                ?>
            </div>
        </div>
        <div class="top-button">
                <?php echo form_button(array('id' => 'submit', 'value' => 'Update', 'name' => 'submit', 'type' => 'submit', 'content' => $this->lang->line('save'),'class' => 'btn btn-primary')); ?>
                <?php echo form_button(array('id' => 'cancelSMS','content' => $this->lang->line('close'),'class' => 'btn btn-danger','onclick'=>'closeFancy()')); ?>
        </div>
    <?php form_close();?>
    <span id="simple-msg-submit"></span>
</div>

<?php $this->load->view('templates/backend/footer'); ?>
<script src="<?php echo STATIC_URL.'backend/js/autoNumeric.js';?>"></script>
<script type="text/javascript">    
$(document).ready(function() {
    $('#amount_send').autoNumeric('init',{aSign:' VNĐ',mDec:0, pSign:'s' });
    $("#amount_send").blur(function() {
        document.getElementById("amount_send_fake").value = UnFormatNumber($('#amount_send').val());
    });
    
    $('#amount_recieve').autoNumeric('init',{aSign:' VNĐ',mDec:0, pSign:'s' });
    $("#amount_recieve").blur(function() {
        document.getElementById("amount_recieve_fake").value = UnFormatNumber($('#amount_recieve').val());
        if(Number($("#amount_recieve_fake").val()) > Number($("#amount_send_fake").val())){
            $("#amount_recieve").focus();
            document.getElementById("amount_recieve").value         = 0;
            document.getElementById("amount_recieve_fake").value    = 0;
            alert("KHÔNG HỢP LỆ! Số tiền nhận không thể lớn hơn số tiền gởi");
            return false;
        } else {
            document.getElementById("amount_send_fake").value       = Number($('#amount_send_fake').val()) - Number($('#amount_recieve_fake').val());
            document.getElementById("amount_send").value            = FormatNumber($('#amount_send_fake').val());
            $("#amount_recieve").attr('readonly','true');
            $("#amount_send").attr('readonly','true');
            
            alert("Số tiền nhập vào hợp lệ! Vui lòng kiểm tra lại số tiền gởi và số tiền nhận!");return false;
        }
    });
    
    $('form').submit(function() {
            $('button[type="submit"]').attr('disabled','disabled');
    });
});

function closeFancy(){
    parent.jQuery.fancybox.close();
}

function FormatNumber(x) {
    if (typeof x === "undefined") {
        return '';
    } else {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + ' VNĐ';
    }
};

function UnFormatNumber(x) {
    if (typeof x === "undefined") {
        return '';
    } else {
    return x.toString().replace(/,|VNĐ|\s/g, "");
    }
};
</script>